package com.liu.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author LIU
 * @version 1.0
 * @description TODO
 * @date 2024/2/20 15:23
 */
public class FutureTaskTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Object> task = new FutureTask<>(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                System.out.println("call task exec");
//                Thread.sleep(20);
                return 1024;
            }
        });

        new Thread(task).start();

        // 未完成 等待
        while (!task.isDone()){
            System.out.println("wait.");
        }

        System.out.println(task.get());

        System.out.println("main thread over");
    }
}
